package com.aruba.paging4.database;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper;

import com.aruba.paging4.database.dao.MovieDao;
import com.aruba.paging4.entity.Movie;

/**
 * Created by aruba on 2021/9/18.
 */
@Database(entities = {Movie.class}, version = 1, exportSchema = true)
public abstract class MyDataBase extends RoomDatabase {
    private static final String DBNAME = "my.db";
    private static MyDataBase instance;

    public static MyDataBase getInstance() {
        if (instance == null) throw new NullPointerException("database not init!!");
        return instance;
    }

    public static synchronized MyDataBase init(Context context) {
        if (instance == null)
            instance = Room.databaseBuilder(context.getApplicationContext()
                    , MyDataBase.class, DBNAME)
                    .fallbackToDestructiveMigration()
                    .build();

        return instance;
    }

    public abstract MovieDao getMovieDao();
}
